#ifndef __ACCEPTOR_H__
#define __ACCEPTOR_H__

#include "Socket.h"
#include "Epoll.h"
#include "InetAddress.h"
#include "TcpConnection.h"

#include <string>
using std::string;
#include <functional>
using std::function;

class Epoll;
class InetAddress;
class TcpConnection;

class Acceptor
{
public:
    Acceptor(string ip, int port, Epoll &poll);

    void bindlisten();
    int fd() {return listenSock_.fd();}

    void setAcceptorCb(std::function<void()> cb);
    int accept();

private:
    void setReuseAddr(bool flag = true);
//    void setReusePort();
    void bind();
    void listen();

    void GetMessageCB(TcpConnection & );

private:
    Socket listenSock_;
    InetAddress addr_;
    TcpConnection conn_;
};

#endif
